# delimit ;  
set more off ;  
local UNIX 0;
drop _all;
program drop _all;
capture log close;
set mem 500m;
set maxvar 32000;
if `UNIX' == 1 {;
		 local saved  "C:\Documents and Settings\g1onb00\My Documents\Eric\hrs\merge\";
		 local wave1d "C:\Documents and Settings\g1onb00\My Documents\Eric\hrs\wave1\";
		 local wave2d "C:\Documents and Settings\g1onb00\My Documents\Eric\hrs\wave2\";
		 local wave3d "C:\Documents and Settings\g1onb00\My Documents\Eric\hrs\wave3\";
		 local wave4d "C:\Documents and Settings\g1onb00\My Documents\Eric\hrs\wave4\";
		 local wave5d "C:\Documents and Settings\g1onb00\My Documents\Eric\hrs\wave5\";
		 local rand "C:\Documents and Settings\g1onb00\My Documents\Eric\hrs\rand\";
};

*Eric;
if `UNIX' == 0  { ;
		 *local saved  "c:\research\hrs\merge\";
		 *local wave1d "c:\research\hrs\wave1\";
		 *local wave2d "c:\research\hrs\wave2\";
		 *local wave3d "c:\research\hrs\wave3\";
		 *local wave4d "c:\research\hrs\wave4\";
		 *local wave5d "c:\research\hrs\wave5\";
		 *local rand   "c:\research\hrs\rand\";
		 local saved  "c:\Dropbox\hrs\merge\";
		 local wave1d "c:\Dropbox\hrs\wave1\";
		 local wave2d "c:\Dropbox\hrs\wave2\";
		 local wave3d "c:\Dropbox\hrs\wave3\";
		 local wave4d "c:\Dropbox\hrs\wave4\";
		 local wave5d "c:\Dropbox\hrs\wave5\";
		 local rand   "d:\Dropbox\hrs\rand\";
		 *local rand "\\econ-san-fs\Home4\uctpkp0\SystemFolder\Windows7\Desktop\hrs\rand\";
};

if `UNIX' == -1 { ;
		 local saved  "C:\Documents and Settings\g1kak01\My Documents\hrs\merge\";
		 local wave1d "C:\Documents and Settings\g1kak01\My Documents\hrs\wave1\";
		 local wave2d "C:\Documents and Settings\g1kak01\My Documents\hrs\wave2\";
		 local wave3d "C:\Documents and Settings\g1kak01\My Documents\hrs\wave3\";
		 local wave4d "C:\Documents and Settings\g1kak01\My Documents\hrs\wave4\";
		 local wave5d "C:\Documents and Settings\g1kak01\My Documents\hrs\wave5\";
		 local rand   "C:\Documents and Settings\g1kak01\My Documents\hrs\rand\";
};


log using "`rand'randreduce.log", replace ;


use "`rand'randhrs1992_2018v2";
sort hhidpn;
compress;

*keep hhidpn h*hhid r*oopmd s*oopmd r*mstat
h*child 
h*ahous h*amort h*ahmln
 h*atran h*aira h*acd h*achck h*astck h*absns h*abond h*aothr h*adebt  h*arles 
h*atotn h*atota
*jcocc 
*jcind  *jhours *lbrf *jhour2 *jweek* 
*wgihr
*higov *cov*
*iearn
*icap
*ipena 
*issdi  *wgihr 
*iunwc
*ifunwc *igxfr
*shlt *hltc 
*iwstat
*jcten
*jyears
*j*
*age*
rabyear  rabmonth ragender raracem  *agem_b
raedyrs *iw* *totmd *hspnit *nrsnit *doctim  *drugs  *outpt  *dentst *ret* h*iothr *work rahisp* 
rarace* rabmonth rabyear *wthh *vetrn; 



gen r1drugs=.;
gen s1drugs=.;
gen r1outpt=.;
gen s1outpt=.;
gen r1dentst=.;
gen s1dentst=.;

* RAND APPEARS TO HAVE GOTTEN RID OF THE TOTAL MEDICAL SPENDING VARIABLE;
gen r1totmd=.;
gen s1totmd=.;
gen r2totmd=.;
gen s2totmd=.;
*gen r3totmd=.;
*gen s3totmd=.;
gen r4totmd=.;
gen s4totmd=.;
gen r5totmd=.;
gen s5totmd=.;
gen r6totmd=.;
gen s6totmd=.;
gen r7totmd=.;
gen s7totmd=.;
gen r8totmd=.;
gen s8totmd=.;
gen r9totmd=.;
gen s9totmd=.;
gen r10totmd=.;
gen s10totmd=.;
gen r11totmd=.;
gen s11totmd=.;
gen r12totmd=.;
gen s12totmd=.;
gen s13totmd=.;
gen r13totmd=.;
gen s14totmd=.;
gen r14totmd=.;

gen r1oopmd=.;
gen s1oopmd=.;
/******************************************************/
* fix up the weird .u and .v missing values;
pause HERE;
local i=1;
* Chris: does this 13 correpond to number of waves? ;
*while `i'<=13 {;
while `i'<=14 {;
	
	replace r`i'oopmd=. if r`i'oopmd>=.;
	replace s`i'oopmd=. if s`i'oopmd>=.;
	replace r`i'mstat=. if r`i'mstat>=.;
	replace h`i'child=. if h`i'child>=.;
	replace h`i'ahous=. if h`i'ahous>=.;
	replace h`i'amort=. if h`i'amort>=.;
	replace h`i'ahmln=. if h`i'ahmln>=.;
	replace h`i'atran=. if h`i'atran>=.;
	replace h`i'aira=. if h`i'aira>=.;
	replace h`i'acd=. if h`i'acd>=.;
	replace h`i'achck=. if h`i'achck>=.;
	replace h`i'acd=. if h`i'acd>=.;      *changed from h`i'cdck;
	replace h`i'astck=. if h`i'astck>=.;
	replace h`i'absns=. if h`i'absns>=.;
	replace h`i'abond=. if h`i'abond>=.;
	replace h`i'aothr=. if h`i'aothr>=.;
	replace h`i'adebt=. if h`i'adebt>=.;
	replace h`i'arles=. if h`i'arles>=.;
	replace h`i'atotn=. if h`i'atotn>=.;

*	replace h`i'atota=. if h`i'atota>=.;
* variable h1atota not found ;

	replace r`i'jcocc=. if r`i'jcocc>=.;
	replace s`i'jcocc=. if s`i'jcocc>=.;
	replace r`i'jcind=. if r`i'jcind>=.;
	replace s`i'jcind=. if s`i'jcind>=.;
	replace r`i'jhours=. if r`i'jhours>=.;
	replace s`i'jhours=. if s`i'jhours>=.;
	replace r`i'work=. if r`i'work>=.;
	replace s`i'work=. if s`i'work>=.;
	replace r`i'jhour2=. if r`i'jhour2>=.;
	replace s`i'jhour2=. if s`i'jhour2>=.;
	replace r`i'jweeks=. if r`i'jweeks>=.;
	replace s`i'jweeks=. if s`i'jweeks>=.;
	replace r`i'jweek2=. if r`i'jweek2>=.;
	replace s`i'jweek2=. if s`i'jweek2>=.;
	replace r`i'jlasty=. if r`i'jlasty>=.;
	replace r`i'jlastm=. if r`i'jlastm>=.;
	replace r`i'iwmid=. if r`i'iwmid>=.;
	replace r`i'wgihr=. if r`i'wgihr>=.;
	replace s`i'wgihr=. if s`i'wgihr>=.;
	replace r`i'jcten=. if r`i'jcten>=.;
	replace s`i'jcten=. if s`i'jcten>=.;
	replace r`i'higov=. if r`i'higov>=.;
	replace r`i'covs=. if r`i'covs>=.;
	replace r`i'covr=. if r`i'covr>=.;
	replace r`i'covrt=. if r`i'covrt>=.;
	replace r`i'iearn=. if r`i'iearn>=.;
	replace s`i'iearn=. if s`i'iearn>=.;
	replace h`i'icap=. if h`i'icap>=.;
	replace r`i'ipena=. if r`i'ipena>=.;
	replace s`i'ipena=. if s`i'ipena>=.;
	replace r`i'isret=. if r`i'isret>=.;
	replace s`i'isret=. if s`i'isret>=.;
	replace r`i'issdi=. if r`i'issdi>=.;
	replace s`i'issdi=. if s`i'issdi>=.;
	replace r`i'iunwc=. if r`i'iunwc>=.;
	replace s`i'iunwc=. if s`i'iunwc>=.;
	replace r`i'igxfr=. if r`i'igxfr>=.;
	replace s`i'igxfr=. if s`i'igxfr>=.;
	replace h`i'iothr=. if h`i'iothr>=.;
	replace r`i'shlt=. if r`i'shlt>=.;
	replace s`i'shlt=. if s`i'shlt>=.;
	*r1hltc ambiguous abbreviation;
	replace r`i'hltc3=. if r`i'hltc3>=.;
* Chris: these exist for early waves only, so commented out. keep?
*	replace r`i'hltc5=. if r`i'hltc5>=.;
	*s1hltc ambiguous abbreviation;
	replace s`i'hltc3=. if s`i'hltc3>=.;
* Chris: these exist for early waves only, so commented out. keep?
*	replace s`i'hltc5=. if s`i'hltc5>=.;
	replace r`i'iwstat=. if r`i'iwstat>=.;
	replace s`i'iwstat=. if s`i'iwstat>=.;
	replace r`i'agey_m=. if r`i'agey_m>=.;
	replace s`i'agey_m=. if s`i'agey_m>=.;
	replace r`i'totmd=. if r`i'totmd>=.;
	replace r`i'hspnit=. if r`i'hspnit>=.;
	replace r`i'nrsnit=. if r`i'nrsnit>=.;
	replace r`i'doctim=. if r`i'doctim>=.;
	replace r`i'drugs=. if r`i'drugs>=.;
	replace r`i'outpt=. if r`i'outpt>=.;
	replace r`i'dentst=. if r`i'dentst>=.;

	replace r`i'jhour2=. if r`i'jhour2>=.;
	replace r`i'jweek2=. if r`i'jweek2>=.;
	replace r`i'jhours=. if r`i'jhours>=.;
	replace r`i'jweeks=. if r`i'jweeks>=.;

	replace r`i'work=. if r`i'work>=.;
	replace r`i'work=. if r`i'work>=.;

	replace s`i'jhour2=. if s`i'jhour2>=.;
	replace s`i'jweek2=. if s`i'jweek2>=.;
	replace s`i'jhours=. if s`i'jhours>=.;
	replace s`i'jweeks=. if s`i'jweeks>=.;

	replace s`i'work=. if s`i'work>=.;
	replace s`i'work=. if s`i'work>=.;


	local i=`i'+1;
};






save "`rand'rndhrs_2018_small.dta", replace;
drop _all;
program drop _all;
log close ;
